#include <stdlib.h>
#include <time.h>

#include <qapplication.h>
#include <qpushbutton.h>

#include "example_g2.h"

MyWindow::MyWindow(QWidget *parent, const char *name)
	: QWidget(parent, name)
{
	setCaption("Main Window");

	QPushButton *quit = new QPushButton("Quit", this, "quit button");
	connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
	quit->setGeometry(10, 10, 80, 30);

	hello = 0;
	createHelloButton();
}

MyWindow::~MyWindow()
{
}

void MyWindow::helloClicked()
{
	qWarning("hello clicked!");
	createHelloButton();
}

void MyWindow::createHelloButton()
{
	if (hello)
		delete hello;
	hello = new QPushButton("Hello!", this, "hello button");
	connect(hello, SIGNAL(clicked()), this, SLOT(helloClicked()));
	hello->setGeometry(10 + rand() % 150, 50 + rand() % 100, 80, 30);
}

int main(int argc, char **argv)
{
	srand(time(0)); // Randomize

	QApplication a(argc, argv);

	MyWindow w(0, "main window");
	w.setGeometry(10, 10, 300, 250);
	a.setMainWidget(&w);
	w.show();

	return a.exec();
}
